package com.lichao.argorithm.impl.array;

import com.lichao.argorithm.api.Stack;

public class ArrayStack<T> implements Stack<T>{
	private final int DEFAULT_SIZE = 16;
	private T[] arr;
	private int length;
	
	public ArrayStack() {
		arr = (T[]) new Object[DEFAULT_SIZE];
	}

	@Override
	public void push(T t) {
		arr[length++] = t;
	}

	@Override
	public T pop() {
		T t = arr[--length];
		arr[length] = null; //help gc
		return t;
	}

	@Override
	public boolean isEmpty() {
		return length == 0;
	}

	@Override
	public int size() {
		return length;
	}

}
